//
//  engine.h
//  bird
//
//  Created by Xiaochen Lian on 5/5/12.
//  Copyright (c) 2012 University of California, Los Angeles. All rights reserved.
//

#ifndef engine_h
#define engine_h

#include "common.h"
#include "body.h"
#include "limb.h"
#include "feather.h"

class CEngine
{
private:
    GLuint program;
    CBody *body;
    // shader
    // camera
    //camera_struct camera;
    //GLfloat fovy, aspect, zNear, zFar;
    // environment
    //point4 light_pos;
    vec4 eye, ref, up;
    GLdouble INIT_PHI, phi_step, phi;
    
    bird_prop bird;
    bird_parameters current_params;
    bird_status current_status;
    bird_dof current_dof;
    
    GLfloat GRAVITY;

public:
    CEngine( /*GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar*/);
    void init();
    void build_scene();
    void init_bird();
    
    void display();
    void display_axis();
    void update(GLdouble timestep);
    
    inline void setBirdParamters(int id, double value)
    {
        current_params.u[id] = value;
    }
    inline bird_status getBirdStatus()
    {
        return current_status;
    }

private:
    void bird_dof_by_params(const bird_parameters &cparams);
    void bird_status_by_params(bird_status &cstatus, const bird_parameters &cparams);
    void aerodynamics(const bird_status &status, const bird_parameters &cparams, const double timestep);
    void update_bird_status(GLdouble timestep);
};

#endif
